<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();
need_auth('admin');


$id = abs(intval($_REQUEST['id']));
$proxy = Table::Fetch('proxy', $id);
$table = new Table('proxy', $_POST);
$uarray = array( 'title', 'bank_name', 'bank_user', 'bank_no', 'kefu_tel', 'biz_tel', 'kefu_qq', 'group_ids', 'city_id', 'is_all_citys'); 
$table->is_all_citys = strtoupper($table->is_all_citys)=='Y' ? 'Y' : 'N';
$table->group_ids = serialize($_POST['group_ids']);

if (!$_POST['title'] || !$_POST['kefu_tel'] || !$_POST['kefu_qq']) {
	Session::Set('error', '名称、客服电话、客服QQ不能为空');
	redirect(null);
}
//print_r($table);exit;

if ( $proxy ) {
	if ( $flag = $table->update( $uarray ) ) {
		Session::Set('notice', '编辑代理商成功');
	} else {
		Session::Set('error', '编辑代理商失败');
	}
} else {
	if ( $flag = $table->insert( $uarray ) ) {
		Session::Set('notice', '新建代理商成功');
	} else {
		Session::Set('error', '新建代理商失败');
	}
}

redirect(null);
